-- kill_obain
-- Created by wangy Apr/19/2016
-- 对敌人造成N点伤害，击杀后概率获得固定奖励
-- 参数列说明：({ value, rand, id, amount})
-- value为固定伤害，rand为奖励的概率，id为奖励的属性或者道具，amount奖励的数量

return {
    apply = function(source, target, classId, value)
        if target.type ~= OBJECT_TYPE_MONSTER then
            -- 目标必须是怪物
            return;
        end

        -- 传入攻击者信息
        local assailantInfo = {
            ["property_id"] = classId,
        };

        local damage = tonumber(value[1]);

        -- 修正伤害值
        damage = PropertyM.fixPropertyDamage(source, target, classId, damage);

        CombatM.doDamage(source, target, damage, 0, false, { assailantInfo = assailantInfo, });

        local bonus;
        if target:isDead() then
            -- 怪物死亡，概率获得
            if DungeonM.getRandSeed("kill_obain") % 1000 <= value[2] then
                local itemId = value[3];
                local amount = value[4];
                if type(itemId) == "number" then
                    bonus = { 1, itemId, amount, };
                elseif type(itemId) == "string" then
                    bonus = { 2, itemId, amount, };
                end

                -- 奖励
                BonusM.doBonus(bonus, "kill_obain");

                if itemId == 1500 then
                    -- 龙珠获得效果
                    local pos = target.dbase:query("pos");
                    if not pos then
                        pos = target:getOwner();
                    end
                    EventMgr.fire(event.PROP_GAIN_DRAGON_BALL, {["bonus"] = bonus,
                        ["pos"] = pos, ["newBonus"] = nil, });
                end
            end
        end

        -- 抛出使用道具攻击事件
        EventMgr.fire(event.PROPERTY_ATTACK, { ["classId"] = classId, ["target"] = target, ["source"] = source});
    end,
}